package com.easybuilder.core.function.service.impl;

import com.easybuilder.core.function.dao.SysGridDao;
import com.easybuilder.core.function.entity.SysGrid;
import com.easybuilder.core.function.service.SysGridService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysGridServiceImpl implements SysGridService {
    @Autowired
    private SysGridDao gridDao;

    /** 插入 */
    @Override
    public int insertSelective(SysGrid grid) {
        return gridDao.insertSelective(grid);
    }

    /** 更新 */
    @Override
    public int updatSelective(SysGrid grid) {
        return gridDao.updateByPrimaryKeySelective(grid);
    }

    /**  查询单个 */
    @Override
    public SysGrid selectOne(SysGrid grid) {

        return gridDao.selectOne(grid);
    }

    /** 按条件删除 */
    @Override
    public int deleteByExample(Object example) {
        return gridDao.deleteByExample(example);
    }

    /** 根据tableId，级联删除grid、gridItem*/
    @Override
    public void casecadeDeleteByTableId(Long id) {
        // 1.先删除gridInfo
        gridDao.casecadeDeleteByTableId(id);
        // 2.删除grid主表
        SysGrid sysGrid = new SysGrid();
        sysGrid.setTableId(id);
        gridDao.delete(sysGrid);
    }
}
